//
//  WPOrderViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/1.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPOrderViewController.h"
#import "WPOrderModel.h"
#import "WPOrderCompeleteCell.h"

static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";

@interface WPOrderViewController ()<UITableViewDataSource, UITableViewDelegate, WPOrderCellDelegate>
@property (nonatomic, strong) UILabel * noMoreLabel;/**< 没有说明 */
@property (nonatomic, strong) UITableView * orderTableView;/**< 订单列表 */
@property (nonatomic, strong) NSMutableArray * orderDataSource;/**< 订单数据源 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */


@end

@implementation WPOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.orderDataSource = [NSMutableArray array];
    WPOrderModel * model = [WPOrderModel new];
    model.orderImage = @"banner1";
    model.orderTitle = @"Rain 王者归来亚洲巡回演唱会";
    model.orderMoeny = @"280";
    model.orderPosition = @"A区 单人票 A-A23";
    model.orderNum = @"1232141432414";
    [_orderDataSource addObject:model];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.noMoreLabel];
    [self.view addSubview:self.orderTableView];
}
#pragma mark - 刷新数据
- (void)refreshData {
    
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _orderDataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WPOrderCompeleteCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[WPOrderCompeleteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.delegate = self;
    [cell refreDataWithModel:_orderDataSource[indexPath.row]];
    return cell;
}
#pragma mark - UITableViewDelegate
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 175*DHFlexibleHorizontalMutiplier();
}
#pragma mark - private protocol
- (void)deleteOrderWithOrderModel:(WPOrderModel *)model {
    [self initializeAlertControllerWithMessageAndDismiss:@"删除订单"];
}
- (void)checkTicketRight {
    [self pushToNextController:[[NSClassFromString(@"WPRightManagerViewController") alloc]init] withVCTitle:@"权益管理"];
}
#pragma mark -getter
- (UILabel *)noMoreLabel {
    if (!_noMoreLabel) {
        _noMoreLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 30*DHFlexibleHorizontalMutiplier())];
            lab.center = self.view.center;
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.text = @"您当前没有已完成订单";
            lab;
        });
    }
    return _noMoreLabel;
}
- (UITableView *)orderTableView {
    if (!_orderTableView) {
        _orderTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.bounces = NO;
            tableview.backgroundColor = [UIColor clearColor];
            tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableview;
        });
    }
    return _orderTableView;
}
@end
